package tcts0421;

import java.util.Arrays;

// https://leetcode-cn.com/problems/master-mind-lcci/
public class 面试题1615珠玑妙算0422 {

        public int[] masterMind(String solution, String guess) {
            int[] res = new int[2];
            char[] s = solution.toCharArray(), g = guess.toCharArray();
            for (int i = 0; i < s.length; i++) {
                if (s[i] == g[i]) {
                    res[0]++;
                    // 已经算作猜中，则不能再后续伪踩中过程中使用，用x标记
                    s[i] = 'x';
                    g[i] = 'x';
                }
            }
            for (int i = 0; i < s.length; i++) {
                if (s[i] == 'x')
                    continue;
                for (int j = 0; j < g.length; j++) {
                    if (g[j] == s[i]) {
                        res[1]++;
                        g[j] = '0'; // guess中的结果已经被算作伪猜中，不能重复被计算，用0标记
                        break;
                    }
                }
            }
            return res;
        }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new 面试题1615珠玑妙算0422().masterMind("RGBY", "GGRR")));
    }

}
